import axios from 'axios'

const request = axios.create({
	baseURL: window.baseURL,
	withCredentials: true, // send cookies when cross-domain requests
	timeout: 300000 // request timeout
})

// 请求拦截
request.interceptors.request.use(
	(config) => {
		config.headers['Authorization'] = { ce: '1' }
		return config
	},
	(error) => {
		console.log(error) // for debug
		return Promise.reject(error)
	}
)
// 响应拦截
request.interceptors.response.use(
	(response) => {
		// console.log(response)
		const res = response.data
		if (response.status !== 200) {
			//错误时也需要传过去
			return Promise.reject(res)
		} else {
			return res
		}
	},
	(error) => {
		if (error.response.status == 500) {
			console.log('500')
		} else {
			console.log('1')
		}
		return Promise.reject(error)
	}
)
export default request
